package WrittenTest;

public class test14 {
    // 大数相乘
    public static void main(String[] args) {
        String ss = "12345";
        String tt = "1234";
        char[] s = new StringBuffer(ss).reverse().toString().toCharArray();
        char[] t = new StringBuffer(tt).reverse().toString().toCharArray();
        int n = ss.length(), m = tt.length();
        int[] nums = new int[n + m];
        // 无进位相乘相加
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                nums[i + j] += ((s[i] - '0') * (t[j] - '0'));
            }
        }
        // 处理进位
        StringBuffer ret = new StringBuffer();
        int c = 0;
        for (int x : nums) {
            c += x;
            ret.append((char) (c % 10 + '0'));
            c /= 10;
        }
        // 处理前导零
        int len = ret.length();
        while (len != 1) {
            if (ret.charAt(len - 1) - '0' == 0) {
                ret.deleteCharAt(len - 1);
                len--;
            } else {
                break;
            }
        }
        System.out.println(new String(ret.reverse()));
    }
}
